package com.sun.pojo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.lang.Nullable;

import javax.annotation.Resource;

/**
 * 注解实现自动装配
 * @Author SunBingRui
 * @Date 2020/5/14 17:44
 */
public class Person {
    //如果显示定义了autowired的required的属性为false，说明这个对象可以为Null
    //@Autowired(required = false)
    @Resource(name = "dog")//Java包下的自动装配注解，也可指定bean的id，默认byName，然后byType实现
    private Dog dog;
    @Autowired
    @Qualifier(value = "cat")//指定bean的id必须为当前value才能自动装配，在环境复杂的时候常用
    private Cat cat;
    private String name;

    public String getName() {
        return name;
    }

    //Nullable注解说明这个属性可以为Null
    public void setName(@Nullable String name) {
        this.name = name;
    }

    public Dog getDog() {
        return dog;
    }

    public void setDog(Dog dog) {
        this.dog = dog;
    }

    public Cat getCat() {
        return cat;
    }

    public void setCat(Cat cat) {
        this.cat = cat;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", dog=" + dog +
                ", cat=" + cat +
                '}';
    }
}
